import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMz0UmGl8Roq432mvfRyZ8PMf1KIDVHd\n' +
  'J7tOLZEKBWplsv0ovnYWtVNbTjItnV0g2htnea2acqET7zVe8p10ejMCAwEAAQ=='

const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAzPRSYaXxGirjfaa9\n' +
  '9HJnw8x/UogNUd0nu04tkQoFamWy/Si+dha1U1tOMi2dXSDaG2d5rZpyoRPvNV7y\n' +
  'nXR6MwIDAQABAkAVsOXnH8DcnB1ndvYzoMgKmOIAwhVmzJkf4a5A42afU+OVyYsU\n' +
  'hW/inPHYil7IfrfExPvhPRODuZn+pHiNct2BAiEA6qulqgRg/uWOQ51bSEITDB+s\n' +
  '8o4xoDcWHg/1WjpyArsCIQDflTwuy3P/8xXPB4bEnMUogLhv3KSWJi+BtY+3Bisa\n' +
  '6QIgBIPq+xt8dksacqibcgd7cFdHr58Wy1tj/I4YDXVkbjMCIAMsOPhpBrJhHrQb\n' +
  'ZTwxBVM30GY1+VfwHsh2bR2pxr7RAiEAzDIxVQ3ywdARc8o9lziFmMJaR9C3QFGO\n' +
  'JRDugseH5n8='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

